package zut.cs.liziflower.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zut.cs.liziflower.entity.Notice;
import zut.cs.liziflower.entity.Result;
import zut.cs.liziflower.service.impl.NoticeServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xuwenke
 * @since 2022-05-21
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController {

    @Resource
    private NoticeServiceImpl noticeService;

    @GetMapping("all-notices")
    public Result<?> getAllNotice() {
        List<Notice> list = noticeService.getAllNotices();
        if (list.isEmpty()) {
            return Result.success();
        }
        return Result.success(list);
    }

    @GetMapping("get-notice-by-id")
    public Result<?> getNoticeByNoticeID(@RequestParam("noticeid") Integer noticeid) {
        Notice notice = noticeService.getNoticeByNoticeID(noticeid);
//        List<Notice> list = noticeService.getAllNotices();
        return Result.success(notice);
    }

}
